package com.tianhui.consignortwofei.other.auth.state;

import android.content.Context;

import com.fgs.common.entity.PictureInfo;
import com.fgs.common.entity.UploadPictureInfo;
import com.fgs.common.uploadPicture.IUploadPicture;
import com.fgs.common.uploadPicture.UploadPicture;
import com.tianhui.consignortwofei.mvp.model.enty.SelectPhotoInfo;
import com.tianhui.consignortwofei.other.auth.inte.SelectPhotoCallback;
import com.tianhui.consignortwofei.other.auth.module.IPictureModule;

/**
 * @author fgs
 * @date 2021/5/13
 * @description 上传
 **/
public class UploadState implements IPictureProcessState {
    private final IPictureModule iPictureModule;

    public UploadState(IPictureModule iPictureModule) {
        this.iPictureModule = iPictureModule;
    }

    private void uploadPicture(Context context, SelectPhotoInfo selectPhotoInfo, SelectPhotoCallback callback) {
        UploadPictureInfo uploadPictureInfo = new UploadPictureInfo();
        uploadPictureInfo.picturePath = selectPhotoInfo.filePath;
        uploadPictureInfo.pictureModule = iPictureModule.pictureModule();
        new UploadPicture(new IUploadPicture.UploadPictureCallback() {
            @Override
            public void onSuccess(UploadPictureInfo uploadPictureInfo, PictureInfo pictureInfo) {
                selectPhotoInfo.pictureId = pictureInfo.id;
                selectPhotoInfo.realFileName = pictureInfo.realFileName;
                callback.selectPhotoSuccess(selectPhotoInfo);
            }

            @Override
            public void onFailed(UploadPictureInfo uploadPictureInfo) {

            }
        }).uploadPicture(context, uploadPictureInfo);
    }

    @Override
    public void stateProcess(Context context, SelectPhotoInfo selectPhotoInfo, SelectPhotoCallback callback) {
        uploadPicture(context, selectPhotoInfo, callback);
    }
}
